package com.emasdemo.util;

import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.View;

import com.emasdemo.R;
import com.emasdemo.activity.ThirdPushPopupActivity;
import com.emasdemo.activity.DeviceActivity;
import com.emasdemo.activity.SettingNoticeActivity;

import static android.content.Context.NOTIFICATION_SERVICE;

public class PushMoreDialog extends AlertDialog{
    private Context mContext;

    public PushMoreDialog(Context context) {
        super(context);
        mContext = context;
    }

    public PushMoreDialog(Context context, int themeResId) {
        super(context, themeResId);
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_push_more);

        findViewById(R.id.action_null).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        findViewById(R.id.action_deviceid).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DeviceActivity.actionStart(mContext);
                dismiss();
            }
        });

        findViewById(R.id.action_settings_notice).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SettingNoticeActivity.actionStart(mContext);
                dismiss();
            }
        });

        findViewById(R.id.action_clear_tips).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (pushMoreInterface != null){
                    pushMoreInterface.clear();
                }
                dismiss();
            }
        });

        findViewById(R.id.action_third_push_activity).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ThirdPushPopupActivity.actionStart(mContext);
                dismiss();
            }
        });

        findViewById(R.id.action_notify).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NotificationManager manager = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
                NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, "8.0up");//该8.0up,对应初始化时的NotificationChannel的id
                builder.setSmallIcon(R.drawable.ic_launcher)//小图标
                        .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher))//大图标
                        .setTicker("这是一个本地通知")//状态栏提示文字
                        .setContentTitle("这是一个本地通知")//标题
                        .setContentText("本地通知创建成功")//内容
                        .setAutoCancel(true)//点击后自动删除
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setColor(Color.RED)//设置颜色
                        .setContentIntent(PendingIntent.getActivity(mContext, 0, new Intent("com.emas.main"), 0))//点击后意图
                        .setWhen(System.currentTimeMillis());
                manager.notify(1, builder.build());//id不能重复，此处只是示例
                dismiss();
            }
        });

    }

    private PushMoreInterface pushMoreInterface;
    public void setPushMoreInterface(PushMoreInterface pushMoreInterface){
        this.pushMoreInterface = pushMoreInterface;
    }

    public interface PushMoreInterface{
        void clear();
    }

}
